package com.bawei.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bawei.mapper.ProviderMapper;
import com.bawei.model.Provider;
import com.bawei.model.ProviderExample;
import com.bawei.model.ProviderExample.Criteria;
import com.bawei.service.ProviderService;
import com.bawei.util.BlankUtil;
@Service
public class ProviderServiceImpl implements ProviderService {
	
	@Autowired
	private ProviderMapper providerMapper;
	
	@Override
	public void addProvider(Provider provider) {
		// TODO Auto-generated method stub
		int a = providerMapper.selectCount();
		a++;
		provider.setgCode("V"+String.format("%03d", a));
		providerMapper.insert(provider);
	}

	@Override
	public void updateProvider(Provider provider) {
		// TODO Auto-generated method stub
		providerMapper.updateByPrimaryKeySelective(provider);
	}

	@Override
	public void delProvider(Long id) {
		// TODO Auto-generated method stub
		providerMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Provider> getProvider() {
		// TODO Auto-generated method stub
		return providerMapper.selectByExample(null);
	}

	@Override
	public Provider getProviderById(Long id) {
		// TODO Auto-generated method stub
		return providerMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Provider> getProviderByCondition(Provider provider) {
		// TODO Auto-generated method stub
		ProviderExample example = new ProviderExample();
		Criteria criteria = example.createCriteria();
		String gCode = provider.getgCode();
		String gName = provider.getgName();
		String gTel = provider.getgTel();
		if(BlankUtil.isNotBlank(gName))
			criteria.andGNameLike("%"+gName+"%");
		if(BlankUtil.isNotBlank(gCode))
			criteria.andGCodeEqualTo(gCode);
		if(BlankUtil.isNotBlank(gTel))
			criteria.andGTelEqualTo(gTel);
		return providerMapper.selectByExample(example);
	}

	@Override
	public void updateStatus(Provider provider) {
		// TODO Auto-generated method stub
		providerMapper.updateStatus(provider);
	}

	@Override
	public void updateStatusNo(Provider provider) {
		// TODO Auto-generated method stub
		providerMapper.updateStatusNo(provider);
	}
	
	
	
}
